zz_

src/min.js

zzmq.dev@gmail.com[dev3]/mathkit[add-isprime-n-function-returns-whether-n] / src / min.js @ 78934f5a Download
Ladder Summary

Implements a min utility that returns the smallest numeric argument, fully mirroring the behavior of the native Math.min—including handling of no arguments (Infinity), NaN propagation, and Infinity edge cases—by delegating directly to Math.min.

+/**
+ * Returns the minimum number from the provided arguments.
+ * Mirrors the behavior of the built‑in Math.min:
+ * - Returns Infinity when called with no arguments.
+ * - Returns NaN if any argument is NaN.
+ *
+ * @param {...number} numbers - A list of numbers to evaluate.
+ * @returns {number} The smallest number, or Infinity / NaN per Math.min semantics.
+ */
+export function min(...numbers) {
+ // Delegating to the native Math.min ensures correct handling of edge cases
+ // such as NaN propagation and Infinity handling.
+ return Math.min(...numbers);
+}